package com.wondersgroup.util;

import java.util.Calendar;
import java.util.Date;

public class TimeUtil {
  /**
   * 获取每天的开始时间 00:00:00:00
   *
   * @param date
   * @return
   */
  public static Date getStartTime(Date date) {
    Calendar dateStart = Calendar.getInstance();
    dateStart.setTime(date);
    dateStart.set(Calendar.HOUR_OF_DAY, 0);
    dateStart.set(Calendar.MINUTE, 0);
    dateStart.set(Calendar.SECOND, 0);
    return dateStart.getTime();
  }

  /**
   * 获取每天的开始时间 23:59:59:999
   *
   * @param date
   * @return
   */
  public static Date getEndTime(Date date) {
    Calendar dateEnd = Calendar.getInstance();
    dateEnd.setTime(date);
    dateEnd.set(Calendar.HOUR_OF_DAY, 23);
    dateEnd.set(Calendar.MINUTE, 59);
    dateEnd.set(Calendar.SECOND, 59);
    return dateEnd.getTime();
  }

  /**
   * @param date
   * @param day 想要获取的日期与传入日期的差值 比如想要获取传入日期前四天的日期 day=-4即可
   * @return
   */
  public static Date getSomeDay(Date date, int day) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.add(Calendar.DATE, day);
    return calendar.getTime();
  }


  public static void main(String[] args) {
    int i=0;
    while(i<5){
        System.out.println("当前日期:：。。。"+getSomeDay(new Date(),i));
        i++;
    }


  }



}

